var e = require;
var t = module;
var o = exports;
var ii, nn = this && this.__extends || (ii = function (t, e) {
    return (ii = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        ii(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }
),
    rr = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        };
var oo = (this && this.__decorate) ||
    function (e, t, a, n) {
        var i,
            o = arguments.length,
            s = o < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, a)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);
        else
            for (var r = e.length - 1; r >= 0; r--)
                (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
        return o > 3 && s && Object.defineProperty(t, a, s), s;
    };
Object.defineProperty(o, "__esModule", { value: !0 });
var a = e("BaseModuleUI"),
    n = e("GlobalParams"),
    i = e("AudioManager"),
    r = e("CommonHelper"),
    s = e("AD"),
    l = cc._decorator,
    _ = l.ccclass,
    c = l.property,
    d = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.free_btn = null),
                (t.video_btn = null),
                (t.not_popup_node = null),
                (t.lucky_box_node = null),
                (t.now_lucky_num = null),
                (t.award_num = 0),
                (t.light_num = 0),
                (t.lucky_box_info = null),
                (t.box_info = [
                    { type: 1, num: 10, name: "钻石" },
                    { type: 0, num: 300, name: "金币" },
                    { type: 3, num: 3, name: "复活币" },
                    { type: 4, num: 1, name: "英雄体验卡" },
                    { type: 1, num: 30, name: "钻石" },
                    { type: 2, num: 5, name: "随机碎片" },
                    { type: 0, num: 100, name: "金币" },
                    { type: 5, num: 1, name: "英雄" }
                ]),
                t
            );
        }
        return (
            nn(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this),
                    (this.lucky_box_info = n.GlobalParams.LuckyBoxInfo.value),
                    (this.not_popup_node.active = this.lucky_box_info.open_today == new Date().toLocaleDateString()),
                    (this.free_btn.active = this.lucky_box_info.get_day != new Date().toLocaleDateString()),
                    (this.video_btn.active = !this.free_btn.active),
                    (this.now_lucky_num.string = "" + this.lucky_box_info.gift_num);
                for (var t = 0, o = this.lucky_box_node.children; t < o.length; t++)
                    o[t].getChildByName("light").active = !1;
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                if ((e.prototype.OnClick.call(this, t), !n.GlobalParams.BoxLightBegin))
                    switch (t.node.name) {
                        case "free_btn":
                            this.showLuckyLight();
                            break;
                        case "video_btn":
                            s.default.getInstance().showVideo(function (e) {
                                i.default.playGameBGM(), e == s.ResultEnum.Success && o.showLuckyLight();
                            });
                            break;
                        case "not_popup":
                            (this.not_popup_node.active = !this.not_popup_node.active),
                                this.not_popup_node.active
                                    ? (this.lucky_box_info.open_today = new Date().toLocaleDateString())
                                    : (this.lucky_box_info.open_today = 0),
                                (n.GlobalParams.LuckyBoxInfo.value = this.lucky_box_info);
                    }
            }),
            (t.prototype.showLuckyLight = function () {
                (n.GlobalParams.BoxLightBegin = !0),
                    this.lucky_box_info.gift_num < 7
                        ? (this.award_num = r.default.getRandomInt(40, 46))
                        : 7 == this.lucky_box_info.gift_num
                            ? (this.award_num = 47)
                            : (this.award_num = r.default.getRandomInt(40, 47)),
                    (this.light_num = 0),
                    this.showLuckyAnime(0.4);
            }),
            (t.prototype.showLuckyAnime = function (e) {
                var t = this,
                    o = this.light_num % 8;
                this.light_num > 0 &&
                    (this.lucky_box_node.children[0 == o ? 7 : o - 1].getChildByName("light").active = !1),
                    (this.lucky_box_node.children[o].getChildByName("light").active = !0),
                    i.default.getInstance().playFx("ding"),
                    this.light_num != this.award_num
                        ? this.scheduleOnce(function () {
                            t.light_num++,
                                e > 0.15 && (e -= 0.05),
                                t.light_num > 35 && (e += 0.05),
                                t.showLuckyAnime(e);
                        }, e)
                        : this.scheduleOnce(function () {
                            var e = t.box_info[o];
                            if (0 == e.type) t.uiManager.addCoinNum(e.num);
                            else if (1 == e.type) t.uiManager.addZsNum(e.num);
                            else if (2 == e.type) t.uiManager.addSpNum(e.num);
                            else if (3 == e.type) t.uiManager.addFhbNum(e.num);
                            else if (4 == e.type) t.uiManager.addTykNum(e.num);
                            else if (5 == e.type)
                                if (t.lucky_box_info.last_award) {
                                    t.lucky_box_info.last_award = !1;
                                    var a = n.GlobalParams.playerSkinInfo.value;
                                    (a.use[0] = 14),
                                        a.have_hero.push(14),
                                        (n.GlobalParams.playerSkinInfo.value = a),
                                        t.uiManager.showPopup("ObtainHeroTipView");
                                } else t.uiManager.addZsNum(30);
                            t.lucky_box_info.gift_num++,
                                (t.lucky_box_info.get_day = new Date().toLocaleDateString()),
                                (n.GlobalParams.LuckyBoxInfo.value = t.lucky_box_info),
                                (t.now_lucky_num.string = "" + t.lucky_box_info.gift_num),
                                t.uiManager.playerTaskOverInfo(2, 1),
                                (t.free_btn.active = t.lucky_box_info.get_day != new Date().toLocaleDateString()),
                                (t.video_btn.active = !t.free_btn.active),
                                (n.GlobalParams.BoxLightBegin = !1),
                                (t.lucky_box_node.children[o].getChildByName("light").active = !1);
                        }, 1);
            }),
            oo([c(cc.Node)], t.prototype, "free_btn", void 0),
            oo([c(cc.Node)], t.prototype, "video_btn", void 0),
            oo([c(cc.Node)], t.prototype, "not_popup_node", void 0),
            oo([c(cc.Node)], t.prototype, "lucky_box_node", void 0),
            oo([c(cc.Label)], t.prototype, "now_lucky_num", void 0),
            oo([_], t)
        );
    })(a.default);
o.default = d;
